using System;
using ProjectBase.Utils;
using Iesi.Collections.Generic;

namespace Clanta.Core.Domain
{
    public class Speaker : VersionDomainObject<long, long>
    {
        #region Constructors

        protected Speaker()
        {
        }

        /// <summary>
        /// Creates a new instance of a speaker with a null email address.
        /// </summary>
        /// <param name="name">The name of the speaker (mandatory).</param>
        /// <param name="conference">The conference that the speaker is assicuated with (mandatory).</param>
        public Speaker(string name, Conference conference)
        {
            Name = name;
            Conference = conference;
        }

        /// <summary>
        /// Creates a new instance of a speaker.
        /// </summary>
        /// <param name="name">The name of the speaker (mandatory)</param>
        /// <param name="email">The email of the speaker (optional)</param>
        /// <param name="conference">The conference that the speaker is associated with (mandatory)</param>
        public Speaker(string name, string email, Conference conference)
        {
            Name = name;
            Conference = conference;
        }

        #endregion

        #region Properties

        /// <summary>
        /// The name of the speaker. Always non-null.
        /// </summary>
        public virtual string Name
        {
            get { return name; }
            set
            {
                Check.Require(!string.IsNullOrEmpty(value), "The name must be provided");
                name = value;
            }
        }

        /// <summary>
        /// Optional email address for the speaker. This value may be null.
        /// </summary>
        public virtual string Email
        {
            get { return email; }
            set { email = value; }
        }

        /// <summary>
        /// The conference associated with the speaker. Always non-null.
        /// </summary>
        public virtual Conference Conference
        {
            get { return conference; }
            protected set
            {
                Check.Require(value != null, "The conference that this speaker belongs to must be provided");
                conference = value;
            }
        }

        /// <summary>
        /// The set of presentations that the speaker is involved in. A
        /// presentation may be shared amongst several speakers belonging to
        /// the same conference.
        /// </summary>
        public virtual ISet<Presentation> Presentations
        {
            get { return presentations; }
            protected set
            {
                Check.Require(value != null, "The presentations that are associated with this speaker must be not be null");
                presentations = value;
            }
        }

        #endregion

        #region Fields

        private string name;

        private string email;

        private Conference conference;

        private ISet<Presentation> presentations = new HashedSet<Presentation>();

        #endregion
    }
}
